/**
 * 项目名称: Topic_844.cpp
 * 项目路径: study/DataStructure/LeetCode/栈/简单
 * 编辑时间: 2024年07月15日09时03分55秒
 * 用   户: 轻尘
 */

#include <bits/stdc++.h>

using namespace std;

bool backspaceCompare(string s, string t) {
    stack<char>stk1;
    stack<char>stk2;

    for(auto x:s)stk1.push(x);
    for(auto x:t)stk2.push(x);

    stack<char>tmp1;
    stack<char>res1;
    stack<char>tmp2;
    stack<char>res2;

    int cnt = 0;
    while (!stk1.empty()){
        char p1 = stk1.top();
        stk1.pop();
        if(p1 == '#')cnt++;
        else if(cnt != 0)cnt--;
        else if(cnt == 0)res1.push(p1);
    }
    cnt = 0;
    while (!stk2.empty()){
        char p1 = stk2.top();
        stk2.pop();
        if(p1 == '#')cnt++;
        else if(cnt != 0)cnt--;
        else if(cnt == 0)res2.push(p1);
    }

    if(res1.size() != res2.size())return false;
    else{
        while (!res1.empty()){
            cout<<res1.top()<<" "<<res2.top();
            if(res1.top() != res2.top())return false;
            res1.pop();
            res2.pop();
        }
        return true;
    }
}

int main() {

    return 0;
}
